using System;
using ShouldIt.Core;

namespace ShouldIt.Clr.Fluent
{
    public class Be<T>
    {
        protected Should<T, Be<T>> should;
        private readonly IAssertProvider assertProvider;

        public Be(Should<T, Be<T>> should, IAssertProvider assertProvider)
        {
            this.should = should;
            this.assertProvider = assertProvider;
        }

        public T Null()
        {
            return Check.IsNull(should, assertProvider);
        }

        public T SameAs(T expected)
        {
            if (should.Negate)
            {
                assertProvider.AreNotSame(expected, should.Target);
            }
            else
            {
                assertProvider.AreSame(expected, should.Target);
            }
            return should.Target;
        }

        public T OfType<TExpectedType>()
        {
            if (should.Negate)
            {
                assertProvider.IsNotInstanceOfType(should.Target, typeof(TExpectedType));
            }
            else
            {
                assertProvider.IsInstanceOfType(should.Target, typeof(TExpectedType));
            }
            return should.Target;
        }

        public T OfType(Type expectedType)
        {
            if (should.Negate)
            {
                assertProvider.IsNotInstanceOfType(should.Target, expectedType);
            }
            else
            {
                assertProvider.IsInstanceOfType(should.Target, expectedType);
            }
            return should.Target;
        }
    }
}